<template>
    <div class="components-container">
        <!-- 编辑 -->
        <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="1400">
            <h3>{{title}} </h3>
            <div style="margin:10px 10px">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开始日期</label>    
                    <div class="layui-input-inline">
                        <el-date-picker v-date type="month" v-model="regList.BSBSTARTDATE" readonly></el-date-picker>
                    </div>
                </div>    
                <div class="layui-inline">
                    <label class="layui-form-label">结存日期</label> 
                    <div class="layui-input-inline">
                        <el-date-picker v-date type="month" v-model="regList.BSBDATE" @change="blanceChange" :readonly="isINFO" :picker-options="pickerOptions0"></el-date-picker>
                    </div>
                </div>
            </div>
           <div class="layui-form-item">
                <!-- <div class="layui-inline">
                    <label class="layui-form-label">结存描述</label>    
                    <div class="layui-input-inline backcolor">
                        <el-date-picker v-date type="date" v-model="regList.BSBDESC" :disabled='isINFO'></el-date-picker>
                    </div>
                </div> -->
                <div class="layui-inline">
                    <label class="layui-form-label">结存描述</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.BSBDESC" style="width:740px;" :disabled='isINFO'></el-input>
                    </div>
                </div>
            </div>
            </div>
            <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
                <table class="layui-table" style="border-spacing: 0;">
                    <colgroup>
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th v-for="item in mxheader">{{item.ColumnName}}</th>
                            <!-- <th>操作</th> -->
                        </tr>
                    </thead>
                    <tbody ref='inputs'>
                        <tr class="allRow" v-for="(chl,index) in chlList">
                             <td width="120px">
                                <el-input v-model="chl.STANAME" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.A" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.B" readonly></el-input>
                            </td>
                            <!-- <td>
                                <el-input v-model="chl.C" readonly></el-input>
                            </td> -->
                             <td>
                                <el-input v-model="chl.D" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.E" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.F" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.G" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.H" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.I" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.J" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.K" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.L" readonly></el-input>
                            </td>
                             <td>
                                <el-input v-model="chl.BBLMONEY" readonly></el-input>
                            </td>
                        </tr>
                    </tbody>
                </table>
              
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancels">取消</el-button>
                <el-button type="primary" @click="submit" :loading="this.$store.state.isloading" v-if="this.title!=='补贴结存详情'">提交</el-button>
            </div>
        </sweet-modal>
    </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>


</style>
<script>
    import sweetModal from "@/components/sweetModal";
    import dataTable from "@/components/Table/DataTable";
    import apiBase from "@/api/apiBase.js";
    import {
        formatDate,
        timeStringToDate,
        dateStringToDate
    } from "@/utils/date.js";
    import {
        manage
    } from "@/mixins/managePage.js";
    const ADD = "新增";
    const MODIFY = "修改";
    const DELETE = "删除";
    const INFO = "详情";
    export default {
        name: "assUseMain",
        mixins: [manage],
        data() {
            return {
                isINFO: true,//详情页面全部不能修改
                maxHeight: 1000,
                chlList: [],
                GetSbsType: [], //获取补贴类型
                QueryNolstaff: [], //获取员工id
                mxheader: [],
                dataModel: [],
                ids: null,
                regList: {
                    // SBSORGID: null,	   //单位编号
                    // SBSTYPE: null, 	   //补贴方式	   A-固定值，B-百分比
                    // SBSCHECKUSR: null,  // 经办人	  
                    SBYDATE: null, //经办日期
                    BSBDATE: null,
                },
                chl: {
                    SBLSTAID: null,	   //员工ID	  
                    SBLCODNAME: null,   //补贴类型
                    SBLMONEY: null,  // 补贴金额
                },
                pickerOptions0: {
                    disabledDate(time) {
                        var data=new Date();
                        data.setDate(1);
                        data.setHours(0);
                        data.setSeconds(0);
                        data.setMinutes(0);
                        return time.getTime() >= Date.parse(data) ;
                    }
                },  
            }
        },
        methods: {
            open(order,id) {
                this.order = order;
                this.ids = id;
                this.getmxheader();//获取明细表头
                
                switch (this.order) {
                    case ADD:
                        this.title = "补贴结存新增";
                        this.dataRepeat();
                        this.getstartdata();
                        this.isINFO = false;
                        this.$refs.dialog.open();
                        break;
                    case INFO:
                        this.title = "补贴结存详情";
                        this.isINFO = true;
                        this.dataInfo(id);
                        this.$refs.dialog.open();
                        break;
                    default:
                }
            },
            //提交
            submit() {
                this.$store.state.isloading = true;
                switch (this.order) {
                    case ADD:
                        this.dataAdd();
                    break;
                    case MODIFY:
                        this.dataModify();
                        break;
                    default:
                }
            },
             //日期更改刷新
            blanceChange(){
                this.QueryBsb();
            },
            //结存物品详情
            getmxheader(){
                 let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Column.GetSearchSubsidyColumns,
                    res => {
                        this.mxheader = res.data.content;
                        this.headList = res.data.content;
                        // let assTypeData = res.data.content,
                        //     legendsUsersData = assTypeData.map(item => ({
                        //         label: item.STAID,
                        //         value: item.STANAME
                        //     }));
                        // this.QueryNolstaff = legendsUsersData;
                });
            },
            // Subsidy/QueryBsb
            QueryBsb(){
                let Data = JSON.parse(JSON.stringify(this.regList));
                if (Data.BSBSTARTDATE)Data.BSBSTARTDATE = formatDate(Data.BSBSTARTDATE, "yyyyMM");
                if (Data.BSBDATE)Data.BSBDATE = formatDate(Data.BSBDATE, "yyyyMM");
                apiBase.DoService(
                    Data,
                    apiBase.getApiAdress().Subsidy.QueryBsb,
                    res => {
                        this.chlList = res.data.content;
                    });
                },
          
             //获取结存起始时间
            getstartdata() {
                apiBase.DoService(
                    {},
                    apiBase.getApiAdress().Subsidy.GetBblStartDate,
                    res => {
                        this.regList.BSBSTARTDATE = res.data.content.StartDate;
                        var now = new Date();
                        if (now.getMonth() == 0){
                            this.regList.BSBDATE = now.getFullYear()-1+'/12'
                        }else {
                            this.regList.BSBDATE = 1900+now.getYear()+"/"+ ("0" + (now.getMonth())).slice(-2);
                        }
                        this.QueryBsb();
                    }
                );
            },
          
           
            //数据重置
            dataRepeat() {
                this.ashUseData = {};
                this.regList = {
                    BSBSTARTDATE: null,
                    BSBDATE: null,
                };
            },
            //新增
            dataAdd() {
                let Data = JSON.parse(JSON.stringify(this.regList));
                let chlList = JSON.parse(JSON.stringify(this.chlList));
                if (Data.BSBSTARTDATE)Data.BSBSTARTDATE = formatDate(Data.BSBSTARTDATE, "yyyyMM");
                if (Data.BSBDATE)Data.BSBDATE = formatDate(Data.BSBDATE, "yyyyMM");
                     if (chlList.length > 0) {
                    Data.list_Bbl = chlList;
                }
                apiBase.DoService(Data, apiBase.getApiAdress().Subsidy.CreateBsb, res => {
                    this.$message({
                        type: "success",
                        message: "新增成功!"
                    });
                    this.cancels();
                    this.refreshData();
                });
            },
           
            //详情
            dataInfo(id) {
                var data = {
                    BSBID: id
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Subsidy.DetailBsb,
                    res => {
                        // this.regList = res.data.content;
                        this.regList.BSBSTARTDATE = res.data.content.BSBSTARTDATEDESC 
                        this.regList.BSBDATE = res.data.content.BSBDATEDESC 
                        this.regList.BSBDESC = res.data.content.BSBDESC;
                        this.chlList = res.data.content.list_Bbl;
                    });
            },
          
            //修改
            dataModify() {
                let chlList = JSON.parse(JSON.stringify(this.chlList));
                let Data = JSON.parse(JSON.stringify(this.regList));
                if (Data.SBYDATE)
                    Data.SBYDATE = formatDate(Data.SBYDATE, "yyyyMMdd");
                if (chlList.length > 0) {
                    Data.list_Bbl = chlList;
                }
                Data.SBYID = this.ids;
                apiBase.DoService(
                    Data,
                    apiBase.getApiAdress().Subsidy.ModifySby,
                    res => {
                        this.refreshData();
                        this.$refs.dialog.close();
                    });
            },
          
            // 页面关闭
            cancels() {
                this.$refs.dialog.close();
            },
            refreshData() {
                this.$emit("refreshData");  //触发父组件的refredata事件
            },
        },
        created() {
           
        },
        components: {
            sweetModal
        }
    };
</script>

